<template>
  <view>
    <view v-for="(card, index) in bankCards" :key="index">
      <view>银行卡号：{{ hiddenCardNumber(card.accountnumber) }}</view>
      <view>支行名称：{{ card.bankforkname }}</view>
      <view>银行名称：{{ card.bankname }}</view>
      ------------------------------------------
    </view>
    <u-button type="success" @click="addbank">添加银行卡</u-button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      bankCards: [], // 银行卡信息数组
      form: {
        id: '0'
      }
    };
  },
  methods: {
    fetchBankCards() {
      this.$api({
        method: 'post',
        url: '/system/userbankinfo/getAccountByIdName',
        data: this.form,
      }).then(res => {
        this.bankCards = res.data;
      }).catch(err => {
        console.log(err);
      });
    },
    addbank() {
      uni.navigateTo({
        url: "/pages/user/my_bank_card/addbank/addbank",
      })
    },
    hiddenCardNumber(cardNumber) {
      // 隐藏银行卡号中间部分
      return cardNumber.substring(0, 4) + " **** **** " + cardNumber.substring(cardNumber.length - 4);
    }
  },
  mounted() {
    this.form.id = uni.getStorageSync('userid');
    this.fetchBankCards();
  }
};
</script>

<style lang="scss">
</style>
